package com.ruibang.glass.equipment.controller;


import com.alibaba.nacos.common.utils.CollectionUtils;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.IubricationManagementReq;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.lubricationManagement;
import com.ruibang.glass.equipment.service.IubricationManagementService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 *周期给油脂管理
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/iubrication/management")
@Api(value = "周期给油脂管理")
public class IubricationManagementController {
    @Autowired
    private IubricationManagementService iubricationManagementService;

    @PostMapping("list")
    @ApiOperation(value = "周期给油脂管理列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody IubricationManagementReq managementReq) {
        return ResultBody.success(iubricationManagementService.queryPage(managementReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody lubricationManagement accidentRegister) {
        return ResultBody.success(iubricationManagementService.updateOrAddById(accidentRegister));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody lubricationManagement accidentRegister) {
        if (CollectionUtils.isNotEmpty(accidentRegister.getIds())) {
            iubricationManagementService.lambdaUpdate().set(lubricationManagement::getIsDelete, Constants.ONE_STR).in(lubricationManagement::getId, accidentRegister.getIds()).update();
        }
        if (StringUtils.isNoneBlank(accidentRegister.getId())) {
            iubricationManagementService.lambdaUpdate().set(lubricationManagement::getIsDelete, Constants.ONE_STR).eq(lubricationManagement::getId,accidentRegister.getId()).update();
        }

        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getOne(@RequestBody lubricationManagement accidentRegister) {
        return ResultBody.success(iubricationManagementService.getById(accidentRegister.getId()));
    }

    @PostMapping("/getStatistics")
    @ApiOperation(value = "统计分析", response = ResultBody.class)
    public ResultBody getStatistics(@RequestBody lubricationManagement accidentRegister) {
        return iubricationManagementService.getStatistics(accidentRegister);
    }
}
